package org.bigjava.controller;

import org.bigjava.bean.Admin;
import org.bigjava.biz.AdminService;
import org.bigjava.common.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {

    @Autowired
    HttpSession session;
    @Autowired
    AdminService adminService;

    //管理员登录
    @RequestMapping("admin/denglu")
    @ResponseBody
    public String adminDengLu(String username, String password){
        Admin admin = adminService.adminDengLu(username,password);
        if(admin == null){
            return "登录失败";
        }else{
            session.setAttribute("admin",admin);
            return "gly.html";
        }
    }

    //管理员个人信息修改
    @RequestMapping("admin/xiugai")
    @ResponseBody
    public String adminXiuGai(String username,String password,String nickname){
        Admin admin = (Admin) session.getAttribute("admin");
        if(username.equals(admin.getUsername()) && password.equals(admin.getPassword()) && nickname.equals(admin.getNickname())){
            return Constant.budon;
        }else{
            admin.setUsername(username);
            admin.setPassword(password);
            admin.setNickname(nickname);
            int a = adminService.adminXiuGai(admin);
            return Constant.hao;
        }
    }
    //管理员注销
    @RequestMapping("admin/zhuxiao")
    public String adminZhuXiao(){
        return "denglu";
    }
    //管理员退出
    @RequestMapping("admin/tuichu")
    public String adminTuiChu(){
        session.invalidate();
        return " denglu";
    }
}
